//
//  MSTemplateView.m
//  testMasory
//
//  Created by xiangbo on 2018/9/20.
//  Copyright © 2018年 xiangbo. All rights reserved.
//

#import "MSDetailBaseView.h"
#import "MSDetailViewController.h"

@interface MSDetailBaseView()

@property (nonatomic, strong) UIButton *actionButton;
@property (nonatomic, strong) UIImage *placeholderImage;

@end

@implementation MSDetailBaseView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.actionButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.actionButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.actionButton];
        
        self.backImage = [[UIImageView alloc] init];
        [self.backImage setImage:[UIImage imageWithColor:MSPlaceholderColor]];
        [self addSubview:self.backImage];
        
        
        self.layer.shadowColor = [UIColor colorWithWhite:0 alpha:0.2].CGColor;
        self.layer.shadowOffset = CGSizeMake(0, 2);//shadowOffset阴影偏移，默认(0, -3),这个跟shadowRadius配合使用
        self.layer.shadowOpacity = 0.8;//0.8;//阴影透明度，默认0
        self.layer.shadowRadius = 4;//8;//阴影半径，默认4
        
        self.layer.cornerRadius = 4;
        self.clipsToBounds = YES;
    }
    return self;
}

- (void)buttonAction:(UIButton *)sender{
    [MSJumpConn jumpControllerWithObject:self.detailData];
}

- (void)setDetailData:(id)detailData{
    _detailData = detailData;
    if ([detailData isKindOfClass:[MSFoodContentModel class]]) {
        MSFoodContentModel *model = detailData;
        [self.backImage setImageWithURL:[NSURL URLWithString:model.cover] placeholder:MSPlaceholderImg];
    }else if ([detailData isKindOfClass:[MSFoodDetailData class]]) {
        MSFoodDetailData *model = detailData;
        [self.backImage setImageWithURL:[NSURL URLWithString:model.img] placeholder:MSPlaceholderImg];
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
